/* SSP Plugin (Stevens Semantic Signal Processing Project)

   Copyright (C) 2011 xxu7@stevens.edu

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#include <config.h>

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "gcc-plugin.h"
#include "plugin.h"
#include "plugin-version.h"

#include "system.h"
#include "coretypes.h"
#include "tm.h"
#include "toplev.h"
#include "gimple.h"
#include "tree-pass.h"
#include "intl.h"
#include "langhooks.h"
#include "cfghooks.h"

#include "ssp-plugin.h"

/* plugin license check */
int plugin_is_GPL_compatible;

/* plugin initialization */
int
plugin_init (struct plugin_name_args *plugin_info,
             struct plugin_gcc_version *version)
{
	const char *name = plugin_info->base_name;
        char *dbname = "ssp_";
        int argc = plugin_info -> argc;
        int i;
        struct plugin_argument *argv = plugin_info->argv;
        struct register_pass_info pass_info;
        printf("// SSPC v0.2 plugin_init \n");
        for (i=0; i < argc; i++){
            printf("key: %s\n", argv[i].key);
            printf("value: %s\n", argv[i].value);
            if (strcmp (argv[i].key, "name") == 0){
                dbname = argv[i].value;
            }
        }
        pass_info.pass = &pass_ssp_io.pass;
        pass_info.reference_pass_name = "optimized";
        pass_info.ref_pass_instance_number = 0;
        pass_info.pos_op = PASS_POS_INSERT_AFTER;
        pass_info.pass->name = dbname;
	//register_callback(name, PLUGIN_PRE_GENERICIZE, sspc_callback, (void *)dbname);
	//register_callback(name, PLUGIN_ALL_IPA_PASSES_START, io_callback, (void *)dbname);
	register_callback(name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
	//register_callback(name, PLUGIN_ALL_PASSES_START, exit_callback, NULL);
        return 0;
}

